fix: preserve literal clone URLs#2172
Merged
Merged
Conversation
4db3773 to
6575026
Compare
Repo.clone_from() expanded environment-variable references in caller-supplied URLs before passing them to git clone. This could expose process environment values to an untrusted remote and made protocol validation apply to a different value than Git received. Polish clone URLs without variable or home expansion on native and Cygwin Git, then apply unsafe-protocol validation to that exact normalized value. Preserve the literal URL when normalizing the stored origin after a successful clone, while retaining the existing Git.polish_url() default for callers that intentionally normalize local paths. Add regression coverage for POSIX and Windows variable syntax, Cygwin conversion, stored origins, and post-normalization protocol validation. Git baseline: git clone passes URL arguments through literally; t/t5601-clone.sh covers the accepted URL forms without shell-style environment expansion. Security: GHSA-rwj8-pgh3-r573. Co-authored-by: Sebastian Thiel <sebastian.thiel@icloud.com>
6575026 to
8ac5a30
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens Repo.clone_from URL handling by preventing environment/~ expansion for clone URLs and for the stored origin URL, aligning GitPython behavior with Git’s literal argument handling and supporting the referenced security advisory.
Changes:
- Add an
expand_varsswitch toGit.polish_urland propagate it throughcygpath/_cygexpath. - In
Repo._clone, use a literal (non-expanding) polished URL for unsafe-protocol validation and for thegit cloneinvocation; also avoid expansion when persistingremote.origin.url. - Add regression tests ensuring clone URLs and stored origin URLs preserve environment-variable-like substrings literally.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/test_clone.py | Adds tests asserting clone URLs and stored origin URLs are not environment-expanded; adds protocol-check regression coverage. |
| git/util.py | Adds expand_vars control to cygpath and _cygexpath to support non-expanding URL polishing on Cygwin. |
| git/repo/base.py | Switches clone URL handling to non-expanding polishing and checks unsafe protocols against the exact value passed to Git; stores origin URL without expansion. |
| git/cmd.py | Extends Git.polish_url with expand_vars (docs + behavior) and uses it to disable env/~ expansion when requested. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tasks
This section is for Byron only. Models continuing this PR must not add, remove, check, uncheck, rename, or reorder checkboxes here.
Everything below this line was generated by
Codex GPT-5.Created by Codex on behalf of Byron. Byron will review before this is ready to merge.
Summary
Preserve caller-provided clone URLs literally when invoking Git and when storing the resulting origin URL. Validate unsafe protocols against the exact normalized value passed to Git. Legacy expansion remains available to callers that intentionally normalize local paths.
Security advisory
GHSA-rwj8-pgh3-r573Advisory summary
gitpython(pip)<= 3.1.50The advisory remains a draft, so this description intentionally omits exploit details.
Validation
pytest test/test_clone.py -q— 20 passed, 1 skippedruff checkon changed files — passedruff format --checkon changed files — passedpytest -q— 681 passed, 73 skipped, 1 xfailed; 7 unrelated local environment/baseline failures (including tests that assume amasterdefault branch and local daemon/config behavior)Git behavior reference
Git passes clone URL arguments through literally;
t/t5601-clone.shexercises accepted clone URL forms without shell-style environment expansion.